<% layout('/layouts/default.html', {title: '种植户信息管理', libs: ['validate']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(ownMedicineGrowerInformation.isNewRecord ? '新增种植户信息' : '编辑种植户信息')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${ownMedicineGrowerInformation}" action="${ctx}/own/ownMedicineGrowerInformation/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<div class="row" id="info" hidden>
					<div class="col-xs-4">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">${text('种子种苗植物名')}：</label>
							<label class="col-sm-8" id="seednm"></label>
						</div>
					</div>
					<div class="col-xs-4">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">${text('种植批次码')}：</label>
							<label class="col-sm-8" id="plantpc"></label>
						</div>
					</div>
					<div class="col-xs-4">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">${text('种植时间')}：</label>
							<label class="col-sm-8" id="planttt"></label>
						</div>
					</div>
				</div>
				<#form:hidden path="id"/>
				<#form:hidden id="ownMedicinePlantInformationId" path="ownMedicinePlantInformationId"/>
				<#form:hidden id="bmBatchCode" path="bmBatchCode"/>
				<div class="row">
					<div class="col-xs-6">
						<!--<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('种植批次号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="batchId" maxlength="25" class="form-control required"/>
							</div>
						</div>-->
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('种植批次号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:listselect id="batchId" title="种植批次号" labelPath="batchId"
								url="${ctx}/own/ownMedicinePlantInformation/findByKey" allowClear="false" checkbox="false"
								itemCode="batchId" itemName="batchId" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('种植户户主姓名')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="principalName" maxlength="50" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('种植户户主身份证')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="principalId" maxlength="18" class="form-control idcard required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('联系电话')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="phone" maxlength="11" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('是否为贫困户')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:radio path="isPoor" dictType="sys_yes_no" class="form-control required" />
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="255" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('own:ownMedicineGrowerInformation:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});
// 选择上级节点回调方法
function treeselectCallback(id, act, index, layero){
	if (id == 'parent' && (act == 'ok' || act == 'clear')){
		// 创建并初始化下一个节点信息，如：排序号、默认值
		$.get('$/own/ownMedicinePlantInformation/findByKey?key='
				+$('#parentCode').val(), function(data){
			$('#treeSort').val(data.treeSort);
		});
	}
}
//选择种植批次号回调方法
function  listselectCallback(id, act, index, layero, selectData) {
	if (id == 'batchId' && (act == 'ok' || act == 'clear')){
		for (let key in selectData){
			$('#ownMedicinePlantInformationId').val(selectData[key]['id']);
			$('#bmBatchCode').val(selectData[key]['bmBatchCode']);
			$("#seednm").text(selectData[key].varietyName);
			$("#plantpc").text(selectData[key].bmBatchCode);
			$("#planttt").text(selectData[key].plantTime);
			$("#info").show();
			break;
		}
	}
}
$(function(){
	var jsaa = "${ownMedicineGrowerInformation.isNewRecord}"; //获取beetl的值
	if (jsaa == 'false'){
		$("#batchIdName").attr("disabled","disabled");
		$("#info").show();
	}

	$.ajax({
		url: "${ctx}/own/ownMedicinePlantInformation/findById",
		type: "get",
		data: {"id": "${ownMedicineGrowerInformation.ownMedicinePlantInformationId}"},
		dataType: "json",
		success: function (data) {
			if (data.ownMedicinePlantInformation){
				$("#seednm").text(data.ownMedicinePlantInformation.varietyName);
				$("#plantpc").text(data.ownMedicinePlantInformation.bmBatchCode);
				$("#planttt").text(data.ownMedicinePlantInformation.plantTime);
			}else {
				js.showErrorMessage("获取错误！", data.msg);
			}
		},
		error: function (e) {
			js.showErrorMessage("错误", e);
		}
	});
});
</script>